﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public enum CacheType
    {
        /// <summary>
        /// 使用内存缓存(不支持分布式)
        /// </summary>
        MemoryCache,

        /// <summary>
        /// 使用内存缓存(分布式)，需要支持序列化
        /// </summary>
        DistributedMemoryCache,

        /// <summary>
        /// 使用其他类型的缓存，如：Redis缓存(支持分布式)
        /// 参考代码：
        /// <![CDATA[
        ///   基本方式：
        ///   services.AddStackExchangeRedisCache(options =>
        ///   {
        ///       // 基本连接配置
        ///       options.Configuration = "localhost:6379";
        ///       
        ///       // 设置要使用的数据库编号（例如使用db1）
        ///       options.ConfigurationOptions = new ConfigurationOptions
        ///       {
        ///           EndPoints = { "localhost:6379" },
        ///           DefaultDatabase = 1  // 关键参数：选择db1
        ///       };
        ///       // 可选：设置缓存键前缀
        ///       options.InstanceName = "MyApp_";
        ///   });
        ///   
        ///  连接字符串方式：
        ///   services.AddStackExchangeRedisCache(options =>
        ///   {
        ///   // 在连接字符串中指定database参数
        ///   options.Configuration = "localhost:6379,defaultDatabase=1,connectTimeout=30000";
        ///   });
        /// 
        ///  多路复用器共享
        ///  // 首先创建复用器
        ///  var multiplexer = ConnectionMultiplexer.Connect("localhost:6379,defaultDatabase=1");
        ///  services.AddSingleton<IConnectionMultiplexer>(multiplexer);
        ///  services.AddStackExchangeRedisCache(options =>
        ///  {
        ///      // 使用已配置的复用器
        ///      options.ConnectionMultiplexerFactory = () => Task.FromResult(multiplexer);
        ///      options.InstanceName = "MyApp_";
        ///  });
        /// 多路复用器共享 - 动态切换库：
        ///  public class CacheService
        ///  {
        ///      private readonly IConnectionMultiplexer _multiplexer;
        ///
        ///      public CacheService(IConnectionMultiplexer multiplexer)
        ///      {
        ///          _multiplexer = multiplexer;
        ///      }
        ///
        ///      public async Task<string> GetFromDatabaseAsync(int dbNumber, string key)
        ///      {
        ///          // 获取指定数据库的引用
        ///          var db = _multiplexer.GetDatabase(dbNumber);
        ///          return await db.StringGetAsync(key);
        ///      }
        ///  }
        /// ]]>
        /// </summary>
        Other
    }
}
